home *** CD-ROM | disk | FTP | other *** search
- unit ntc_client_info;
- {
- Copyright (C) 2004 - 2006 Andrew Sprott
-
- http://astronomy.crysania.co.uk
- astro@trefach.co.uk
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; either version 2
- of the License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- }
-
- interface
-
- uses
- Windows,
- Messages,
- SysUtils,
- Variants,
- Classes,
- Graphics,
- Controls,
- Forms,
- Dialogs,
- StdCtrls,
- ExtCtrls,
- inifiles,
- Buttons,
-
- ntc_client_form,
- ntc_client_network,
- ntc_client_control,
- ntc_client_object;
-
- const
- default_refresh_rate=30000;
-
- type
- Tscope_info = class(tform)
- info_panel: TPanel;
- coord_box: TGroupBox;
- ra_label: TLabel;
- alt_label: TLabel;
- dec_label: TLabel;
- az_label: TLabel;
- hours_label: TLabel;
- ra_minutes_label: TLabel;
- ra_seconds_label: TLabel;
- degrees_label: TLabel;
- minutes_label: TLabel;
- seconds_label: TLabel;
- refresh_rate_label: TLabel;
- dec_degrees_edit: TEdit;
- alt_degrees_edit: TEdit;
- az_degrees_edit: TEdit;
- ra_hours_edit: TEdit;
- ra_minutes_edit: TEdit;
- ra_seconds_edit: TEdit;
- dec_minutes_edit: TEdit;
- dec_seconds_edit: TEdit;
- az_minutes_edit: TEdit;
- az_seconds_edit: TEdit;
- alt_minutes_edit: TEdit;
- alt_seconds_edit: TEdit;
- info_label: TLabel;
- get_ra_dec_button: TBitBtn;
- get_alt_az_button: TBitBtn;
- get_all_button: TBitBtn;
- controller_timer: TTimer;
- refresh_rate_edit: TEdit;
- msecs_label: TLabel;
- timer_button: TBitBtn;
-
- { form functions }
- procedure formcreate(
- Sender:TObject);
-
- procedure form_close_query(
- Sender: TObject;
- var CanClose: Boolean);
-
- { information retrieval }
- procedure get_info;
-
- Procedure show_info;
-
- procedure get_ra_dec;
-
- procedure get_az_alt;
-
- { configuration }
- procedure load_settings;
-
- procedure save_settings;
-
- { events }
- procedure FormShow(
- Sender: TObject);
-
- procedure adjust;
-
- procedure check_activate(
- Sender: TObject);
-
- procedure refresh_rate_editChange(
- Sender: TObject);
-
- procedure get_ra_dec_buttonClick(
- Sender: TObject);
-
- procedure get_alt_az_buttonClick(
- Sender: TObject);
-
- procedure get_all_buttonClick(
- Sender: TObject);
-
- procedure timer_buttonClick(
- Sender: TObject);
-
- procedure controller_timerTimer(
- Sender: TObject);
-
- private
- { global information }
- public
- { Public declarations }
- info_string:string;
- { configuration }
- dimensions:dimensions_record;
- refresh_rate:integer;
-
- { events }
- procedure check_visible_and_show_hide(
- sender:tobject);
-
- procedure hide_form;
- procedure show_form;
- end;
-
- var
- scope_info: Tscope_info;
-
- implementation
-
- uses
- ntc_client_focus,
- ntc_client_tracking,
- ntc_client_search;
-
- {$R *.dfm}
-
- { --------------
- form functions
- -------------- }
-
- procedure Tscope_info.formcreate(
- Sender:TObject);
- begin
- controller_timer.enabled:=false;
- load_settings;
- end;
-
- procedure Tscope_info.form_close_query(
- Sender: TObject;
- var CanClose: Boolean);
- begin
- canclose:=false;
- visible:=false;
- with dimensions do
- begin
- form_top:=top;
- form_left:=left;
- end;
- end;
-
- { ---------------------
- information retrieval
- --------------------- }
-
- Procedure tscope_info.show_info;
- var
- h:hms;
- d:dms;
- a:ams;
- begin
- with current_object do
- begin
- right_ascension_str(h);
- with h do
- begin
- ra_hours_edit.text:=inttostr(hours);
- ra_minutes_edit.text:=inttostr(minutes);
- ra_seconds_edit.text:=inttostr(seconds);
- end;
- declination_str(d);
- with d do
- begin
- dec_degrees_edit.text:=inttostr(degrees);
- dec_minutes_edit.text:=inttostr(minutes);
- dec_seconds_edit.text:=inttostr(seconds);
- end;
- azimuth_str(d);
- with d do
- begin
- az_degrees_edit.text:=inttostr(degrees);
- az_minutes_edit.text:=inttostr(minutes);
- az_seconds_edit.text:=inttostr(seconds);
- end;
- altitude_str(a);
- with a do
- begin
- alt_degrees_edit.text:=inttostr(degrees);
- if (degrees<0) or (degrees>90) then
- begin
- scope_control.stop_scope;
- alt_degrees_edit.Color:=clRed
- end
- else
- alt_degrees_edit.Color:=clWindow;
- alt_minutes_edit.text:=inttostr(minutes);
- alt_seconds_edit.text:=inttostr(seconds);
- end;
- end;
- with info_label do
- begin
- caption:=info_string;
- width:=240;
- end;
- end;
-
- procedure tscope_info.get_info;
- var
- s:string;
- begin
- with scope_network,scope_control,scope_focus,scope_tracking do
- if (send_request_check('get_info')=[exit_ok]) and
- get_string('name',s) and
- get_boolean('can_goto',can_goto) and
- get_boolean('can_sync',can_sync) and
- get_boolean('can_slew',can_slew) and
- get_boolean('can_focus',can_focus) and
- ((can_focus and get_integer('focus_speeds',focus_speeds)) or
- not can_focus) and
- get_boolean('can_track',can_track) then
- begin
- name:=shortstring(s);
- scope_name:=name;
- end
- else
- begin
- name:='';
- scope_name:='unknown scope';
- end;
- end;
-
- procedure tscope_info.get_ra_dec;
- begin
- with scope_network,scope_control,scope_focus,current_object do
- if (send_request_check('get_ra_dec')=[exit_ok]) and
- get_float('ra',ra) then
- get_float('dec',dec);
- end;
-
- procedure tscope_info.get_az_alt;
- begin
- with scope_network,scope_control,scope_focus,current_object do
- if (send_request_check('get_az_alt')=[exit_ok]) and
- get_float('alt',alt) then
- get_float('az',az);
- end;
-
- { -------------
- configuration
- ------------- }
-
- procedure tscope_info.load_settings;
- begin
- ini_file:=tinifile.create(application_path+'client.ini');
- with ini_file do
- begin
- refresh_rate:=readinteger('info','refresh_rate',default_refresh_rate);
- { form }
- scope.get_dimensions(scope_info,@dimensions,'info',ini_file);
- left:=dimensions.form_left;
- top:=dimensions.form_top;
- visible:=readbool('info','visible',false);
- end;
- ini_file.free;
- end;
-
- procedure tscope_info.save_settings;
- begin
- ini_file.writeinteger('info','refresh_rate',refresh_rate);
- { form }
- scope.find_vdu(scope_info,@dimensions);
- scope.write_dimensions(@dimensions,left,top,'info',ini_file);
- ini_file.writebool('info','visible',visible);
- end;
-
- { ------
- events
- ------ }
-
- procedure Tscope_info.FormShow(
- Sender: TObject);
- begin
- with dimensions do
- begin
- top:=form_top;
- left:=form_left;
- end;
- end;
-
- procedure tscope_info.adjust;
- begin
- with dimensions do
- begin
- form_top:=trunc(form_top/last_screen_height*current_height);
- form_left:=trunc(form_left/last_screen_width*current_width);
- end;
- if visible then
- show;
- end;
-
- procedure tscope_info.check_visible_and_show_hide(
- sender:tobject);
- begin
- if visible then
- hide_form
- else
- show_form;
- scope.show_hide(sender,visible);
- end;
-
- procedure tscope_info.hide_form;
- begin
- with dimensions do
- begin
- form_top:=top;
- form_left:=left;
- end;
- Visible:=false;
- end;
-
- procedure tscope_info.show_form;
- begin
- Visible:=true;
- end;
-
- procedure Tscope_info.check_activate(
- Sender: TObject);
- begin
- scope.form_activate(scope_info,@dimensions);
- end;
-
- procedure Tscope_info.refresh_rate_editChange(
- Sender: TObject);
- begin
- refresh_rate:=strtointdef(refresh_rate_edit.text,0);
- if refresh_rate<5000 then
- begin
- refresh_rate:=5000;
- refresh_rate_edit.text:=inttostr(refresh_rate);
- end;
- end;
-
- procedure Tscope_info.get_ra_dec_buttonClick(
- Sender: TObject);
- begin
- get_ra_dec;
- show_info;
- end;
-
- procedure Tscope_info.get_alt_az_buttonClick(
- Sender: TObject);
- begin
- get_az_alt;
- show_info;
- end;
-
- procedure Tscope_info.get_all_buttonClick(
- Sender: TObject);
- begin
- get_ra_dec;
- get_az_alt;
- show_info;
- end;
-
- procedure Tscope_info.timer_buttonClick(
- Sender: TObject);
- begin
- if controller_timer.enabled then
- begin
- controller_timer.Enabled:=false;
- timer_button.caption:='Start';
- end
- else
- begin
- timer_button.caption:='Stop';
- controller_timer.Interval:=refresh_rate;
- controller_timer.enabled:=true;
- end;
- end;
-
- procedure Tscope_info.controller_timerTimer(
- Sender: TObject);
- begin
- if scope_network.scope_client.connected and
- not scope_network.network_timer.enabled then
- begin
- get_info;
- show_info;
- end;
- end;
-
- end.